package com.yhhvip.user.dao;

import com.yhhvip.user.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;


@Repository
public interface UserDao  extends JpaRepository<User,Integer>,JpaSpecificationExecutor<User> {
   @Query(value = " from User user where (user.phoneNumber=?1 or user.wxunionid=?2) ")
    User IsUser(String phone, String Wxunionid);
    @Query(value = " from User user where  user.wxunionid=?1 ")
    User IsUserByWxunionid(String Wxunionid);

    @Query(value = " from User user where user.phoneNumber=?1 ")
    User IsUserByPhone(String phone);
    //
    /*@Query(value = "insert into TestUser user set user.userName=?1 where user.userId=?2")
    @Modifying
    Integer addUserByPhone(String PhoneNumber);*/
    @Transactional
    @Modifying//更新查询
    @Query(value ="update User user set user.wxunionid =?1,user.headPortrait =?2,user.nickName =?3 where user.userId =?4")
    int setbindWeChat(String Wxunionid, String headPortrait, String nickName, Integer userId);
    @Transactional
    @Modifying//更新查询
    @Query(value ="update User user set user.phoneNumber = ?1 where user.userId =?2")
    int setbindPhone(String phone, Integer userId);

    @Query(value = " from User user where user.invitationCode=?1")
    User IsinvitationCode(String invitationCode);

   @Query(value = "select user from User user where user.userId=?1")
   Page<User> selectUserIdPage(Integer userId, Pageable pageable);


}
